package com.xu.cloud.auth.config;

import com.xu.cloud.auth.interceptor.AccessTokenAuthInterceptor;
import com.xu.cloud.common.util.ResourceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * 基础配置类
 *
 * @author xuguan
 * @since 2025/2/23
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private AccessTokenAuthInterceptor accessTokenAuthInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(accessTokenAuthInterceptor)
                .excludePathPatterns(excludePathPatterns());
    }

    private List<String> excludePathPatterns() {
        final List<String> excludePathPatterns = new ArrayList<>(ResourceUtil.openUrlPatterns);
        excludePathPatterns.addAll(ResourceUtil.staticUrlPatterns());
        return excludePathPatterns;
    }
}
